<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title a m-cf">站内信列表</div>
                </div>
                <div class="widget-body am-fr">


                    <div class="widget-body am-fr">
                        <!-- 工具栏 -->
                        <div class="page_toolbar am-margin-bottom-xs am-cf">
                            <form id="form-search" class="toolbar-form" action="">
                                <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                                <div class="am-u-sm-12 am-u-md-9" style="float: right;">
                                    <div class="am fr">
                                        <div class="am-form-group am-fl">
                                            <?php $is_see = $request->get('is_see'); ?>
                                            <select name="is_see"
                                                    data-am-selected="{btnSize: 'sm', placeholder: '状态'}">
                                                <option value=""></option>
                                                <option value="-1" <?= $is_see === '-1' ? 'selected' : '' ?>>全部</option>
                                                <option value="0" <?= $is_see === '0' ? 'selected' : '' ?>>未查看</option>
                                                <option value="1"<?= $is_see === '1' ? 'selected' : '' ?>>查看</option>
                                            </select>
                                        </div>
                                        <div class="am-form-group am-fl">
                                            <?php $type = $request->get('type'); ?>
                                            <select name="type"
                                                    data-am-selected="{btnSize: 'sm', placeholder: '类型'}">
                                                <option value=""></option>
                                                <option value="-1" <?= $type === '-1' ? 'selected' : '' ?>>全部</option>
                                                <option value="1" <?= $type === '1' ? 'selected' : '' ?>>系统通知</option>
                                                <option value="2"<?= $type === '2' ? 'selected' : '' ?>>用户通知</option>
                                            </select>
                                        </div>
                                        <div class="am-form-group tpl-form-border-form am-fl">
                                            <input type="text" name="start_time"
                                                   class="am-form-field"
                                                   value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                                   data-am-datepicker readonly>
                                        </div>
                                        <div class="am-form-group tpl-form-border-form am-fl">
                                            <input type="text" name="end_time"
                                                   class="am-form-field"
                                                   value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                                   data-am-datepicker readonly>
                                        </div>
                                        <div class="am-form-group am-fl">
                                            <div class="am-input-group am-input-group-sm tpl-form-border-form">

                                                <div class="am-input-group-btn" style="width: auto;">
                                                    <button class="am-btn am-btn-default am-icon-search"
                                                            type="submit"></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>

                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>标题</th>
                                <th>类型</th>
                                <th>状态</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['id'] ?></td>
                                    <td class="am-text-middle"><?= $item['title'] ?></td>
                                    <td class="am-text-middle"><?= $item['type']['text'] ?></td>
                                    <td class="am-text-middle"><?= $item['is_see']['text'] ?></td>
                                    <td class="am-text-middle"><?= $item['create_time'] ?></td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if (checkPrivilege('store.letter/detail')): ?>
                                                <a class="j-recharge tpl-table-black-operation-default"
                                                   href="javascript:void(0);"
                                                   title="详情"
                                                   data-id="<?= $item['id'] ?>"
                                                   data-balance="<?= $item['content'] ?>"
                                                >
                                                    <i class="am-icon-pencil"></i>
                                                    详情
                                                </a>
                                            <?php endif; ?>
                                            <?php if (checkPrivilege('store.letter/delete')): ?>
                                                <a href="javascript:void(0);"
                                                   class="item-delete tpl-table-black-operation-del"
                                                   data-id="<?= $item['id'] ?>">
                                                    <i class="am-icon-trash"></i> 删除
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="6" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 模板：用户充值 -->
<script id="tpl-recharge" type="text/template">
    <div class="am-padding-xs am-padding-top-sm">
        <form class="am-form tpl-form-line-form" method="post" action="">
            <div class="j-tabs am-tabs">
                <div class="am-tabs-bd am-padding-xs">
                    <div class="am-tab-panel am-padding-0 am-active" id="tab1">
                        <div class="am-form-group">
                            <div class="am-u-sm-8 am-u-end">
                                <div class="am-form--static">{{ balance }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>
<script>
    $(function () {
        /**
         * 账户充值
         */
        $('.j-recharge').on('click', function () {
            var $tabs, data = $(this).data();
            $.getJSON("<?= url('store.letter/see') ?>&id="+data.id,function(result){

            });


            $.showModal({
                title: '详情'
                , area: '460px'
                , content: template('tpl-recharge', data)
                , uCheck: true
                , success: function ($content) {
                    $tabs = $content.find('.j-tabs');
                    $tabs.tabs({noSwipe: 1});
                }
                , yes: function ($content) {
                    $content.find('form').myAjaxSubmit({
                        url: '<?= url('store.letter/see') ?>',
                        data: {
                            id: data.id,
                            source: $tabs.data('amui.tabs').activeIndex
                        }
                    });
                    return true;
                }
            });
        });

        // 删除元素
        var url = "<?= url('store.letter/delete') ?>";
        $('.item-delete').delete('id', url, '删除后不可恢复，确定要删除吗？');

    });
</script>

